<?php

class Router {
    
    public function routing ($uri) {
        
        if ($uri == '/index.php' || $uri == '/' || $uri == '') {
            $uri = '/index.php/';
        }
        $match = array();
        
        $app = implode('|', Config::get('application'));

        preg_match("~^/(index\.php/)?($app)?/?([0-9a-z_%\-+/\?=\.]*)$~i", $uri, $match);
        
        if (!empty($match[2])) {
            define('APP_NAME', strtolower($match[2]));
        } else {
            define('APP_NAME', Config::get('application','default'));
        }
        define('APP_PATH', ROOT_PATH . 'app' . DIRECTORY_SEPARATOR . APP_NAME . DIRECTORY_SEPARATOR);
        
        $array = array(
            array('~shop/(\d)~') , 
            array(
                'shop/listgoods/id/$1'));
        
        return preg_replace($array[0], $array[1], $match[3]);
    
    }
}
?>